package cn.bugstack.springframework.test;

import java.util.Arrays;
import java.util.List;

public class SumThreadDemo {

    static class SumThread extends Thread {

        private List<Integer> originData;

        public long sum;

        public SumThread(List<Integer> originData) {
            this.originData = originData;
        }

        public Long getSum() {
            return sum;
        }


        @Override
        public void run() {
            for (Integer item : originData) {
                sum = item + sum;
            }

        }
    }

    public static void main(String[] args) {
        try {
            List<Integer> data1 = Arrays.asList(1, 2, 3);
            SumThread sumThread = new SumThread(data1);
            List<Integer> data2 = Arrays.asList(4, 5, 6);
            SumThread sumThread2 = new SumThread(data2);
            sumThread.start();
            sumThread2.start();
            sumThread.join();
            sumThread2.join();
            System.out.println(sumThread.getSum() - sumThread2.getSum());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

    }
}